var _base = "http://172.16.24.122:8080";//智慧
// var _base = "http://demo.sqsh365.com:7001"//上海测试
//var _base = "http://221.0.79.248:8082";//正式
//var _baseUrl = _base + '/WebDemo'; //服务WebDemo
var _baseUrl = _base + '/ytyyjh'; //服务
//var _baseUrl = _base + '/ytyyjhcs'; //测试服务
//var userID=localStorage.userId ? localStorage.userId.split(","):[];
localStorage.ip=_base;
//localStorage.ip='http://demo.sqsh365.com:7001' 
var Url = {
	PGAPPLY_CHECK: _baseUrl + "/rest/medical/account/check", //用户验证
	ASSESS_SERVICES: _baseUrl + "/rest/medical/assess/services", //服务列表
	ASSESS_TODAY: _baseUrl + "/rest/medical/assess/today", //今日任务列表
	ASSESS_SCHEDULE: _baseUrl + "/rest/medical/assess/schedule", //获取排班列表
	ASSESS_WORKLIST: _baseUrl + "/rest/medical/assess/workOrderList", //评估任务列表
	ASSESS_MEDICAL: _baseUrl + "/rest/medical/assess/medicalCare", //上门医护列表
	ASSESS_QUESTION: _baseUrl + "/rest/medical/assess/questionList", //上门医护录入题目
	ASSESS_DEUGLIST: _baseUrl + "/rest/medical/assess/drugWorkOrderList", //医药配送列表
	ASSESS_DEUGORDER: _baseUrl + "/rest/medical/assess/updateDrugOrderStatus", //医药药品领取,药品签收
	ASSESS_WAIT: _baseUrl + "/rest/medical/assess/waitToReceiveOrder", //医药药品领取,药品签收
	ASSESS_WAITLIST: _baseUrl + "/rest/medical/assess/drugOrderListDetail", //上门送药，待接单详情
	ASSESS_SAVEDRUG: _baseUrl + "/rest/medical/assess/saveDrugOrder", //上门送药，接单
	ASSESS_SAVASSESS: _baseUrl + "/rest/medical/assess/saveAssess", //上门评估，提交答案
	ASSESS_CHECKIN: _baseUrl + "/rest/medical/assess/checkIn", //上门医护签到
	ASSESS_CHECKOUT: _baseUrl + "/rest/medical/assess/checkOut", //上门医护签退
	ASSESS_SMPCHECKIN: _baseUrl + "/rest/medical/assess/smpgCheckIn", //上门评估签到
	ASSESS_SMPCHECKOUT: _baseUrl + "/rest/medical/assess/smpgCheckOut", //上门评估签到
	ASSESS_CHECKININFO: _baseUrl + "/rest/medical/assess/checkInAndOutInfo", //上门医护拍照查询
	ASSESS_INFOBYZJHM: _baseUrl + "/rest/medical/assess/checkElderInfoByZjhm", //评估服务根据身份证获取老人信息
	ASSESS_ELDERINFO: _baseUrl + "/rest/medical/assess/elderInfo", //评估服务老人信息查询
	ASSESS_UPDATEINFO: _baseUrl + "/rest/medical/assess/updateElderInfo", //评估服务老人老人信息修改
	ASSESS_ADDINFO: _baseUrl + "/rest/medical/assess/addElderInfo", //评估服务老人信息增加
	ASSESS_FINDVATE: _baseUrl + "/rest/medical/assess/findEvaluate", //评估信息查询
	ASSESS_CXPGCS: _baseUrl + "/rest/medical/assess/cxpgcs", //评估次数获取
	ASSESS_EVSVATE: _baseUrl + "/rest/medical/assess/evauateCount", //服务评估次数获取
	ASSESS_ADDEVALUATE: _baseUrl + "/rest/medical/assess/addEvaluate", //评估服务增加评估
	ASSESS_GETDIC: _baseUrl + "/rest/medical/assess/getDictionary", //评估服务增加评估
	ASSESS_ZANCUN: _baseUrl + "/rest/medical/assess/saveTOrderEvaluateResultZc", //评估服务暂存
	ASSESS_ZANCUNSANCHU: _baseUrl + "/rest/medical/assess/deleteTOrderEvaluateResultZc", //评估服务暂存删除
	ASSESS_ZANCUNCHAXUN: _baseUrl + "/rest/medical/assess/selectTOrderEvaluateResultZc", //评估服务暂存查询
	ASSESS_ZANCUNCXLIST: _baseUrl + "/rest/medical/assess/selectTOrderEvaluateResultZcPGLX", //评估服务暂存查询列表
	ASSESS_GETJG: _baseUrl + "/rest/medical/assess/getjg", //评估服务机构
	
}
//ios heard适配
var iosipone = false;
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/iPhone\sOS/i) == "iphone os") {
	iosipone = true;
	$('body').prepend('<div style="height: 18px;background: #698af3;"></div>')
}
//lodding
function showLoading() {
	if($('body').find('.allcommomn_backdrop').length == 0) {
		$('body').append('<div class="allcommomn_backdrop"><div class="CoverLayer"></div><div class="allcommomn_backdrop1 textC radius10P"><img class="height3R" src="../../img/home/loading.gif" onerror="this.src=\'img/home/loading.gif\'" /></div></div>');
		delete index;
	} else {
		$('body').find('.allcommomn_backdrop').show();
	}
}

function hideLoading() {
	$('body').find('.allcommomn_backdrop').hide();
}

function ajaxGet(url, data, successCallback, errorCallback) {
	showLoading();
	$.ajax({
		type: "GET",
		url: url,
		headers: {
			"userId": JSON.parse(localStorage.user_info || '{}').userId,
			"token": JSON.parse(localStorage.user_info || '{}').token,
//			"AUTH_KEY_JKCS_YSD": JSON.parse(localStorage.token).AUTH_KEY_JKCS_YSD,
//			"AUTH_KEY_JKCS_YSDtimestamp": JSON.parse(localStorage.token).AUTH_KEY_JKCS_YSDtimestamp,
//			"state": 'ysd'
		},
		data: data,
		timeout: '30000',
		success: function(data) {
			hideLoading()
			if(typeof(data) === 'string'){
				data = JSON.parse(data);
			}
			if(data.code == 'ERROR-AUTH-UNLOGIN_AUTH_KEY_JKCS_YSD') {
				//询问框
				layer.open({
					content: '登陆信息超时，请重新登陆？',
					btn: ['退出'],
					yes: function(index) {
						window.AndroidWebView.sendBroad();
						layer.close(index);
					}
				});
			} else {
				successCallback(data);
			}
			
		},
		error: function() {
			hideLoading()
			console.log("请求失败")
			if(errorCallback) {
				errorCallback()
			}
		}
	});
}

function ajaxPostJson(url, data, successCallback, errorCallback) {
	showLoading();
	$.ajax({
		type: "post",
		url: url,
		headers: {
			"userId": JSON.parse(localStorage.user_info || '{}').userId,
			"token": JSON.parse(localStorage.user_info || '{}').token,
//			"AUTH_KEY_JKCS_YSD": JSON.parse(localStorage.token).AUTH_KEY_JKCS_YSD,
//			"AUTH_KEY_JKCS_YSDtimestamp": JSON.parse(localStorage.token).AUTH_KEY_JKCS_YSDtimestamp,
//			"state": 'ysd'
		},
		contentType: "application/json",
		data: JSON.stringify(data),
		timeout: '30000',
		success: function(data) {
			hideLoading()
			if(typeof(data) === 'string'){
				data = JSON.parse(data);
			}
			if(data.code == 'ERROR-AUTH-UNLOGIN_AUTH_KEY_JKCS_YSD') {
				//询问框
				layer.open({
					content: '登陆信息超时，请重新登陆？',
					btn: ['退出'],
					yes: function(index) {
						window.AndroidWebView.sendBroad();
						layer.close(index);
					}
				});
			} else {
				successCallback(data);
			}
		},
		error: function() {
			hideLoading()
			console.log("请求失败")
			log_message("无数据")
			if(errorCallback) {
				errorCallback()
			}
		}
	});
}

function ajaxPost(url, data, successCallback, errorCallback) {
	showLoading();
	$.ajax({
		type: "post",
		url: url,
		headers: {
			"userId": JSON.parse(localStorage.user_info || '{}').userId,
			"token": JSON.parse(localStorage.user_info || '{}').token,
//			"AUTH_KEY_JKCS_YSD": JSON.parse(localStorage.token).AUTH_KEY_JKCS_YSD,
//			"AUTH_KEY_JKCS_YSDtimestamp": JSON.parse(localStorage.token).AUTH_KEY_JKCS_YSDtimestamp,
//			"state": 'ysd'
		},
		data: data,
		timeout: '30000',
		success: function(data) {
			hideLoading()
			if(typeof(data) === 'string'){
				data = JSON.parse(data);
			}
			if(data.code == 'ERROR-AUTH-UNLOGIN_AUTH_KEY_JKCS_YSD') {
				//询问框
				layer.open({
					content: '登陆信息超时，请重新登陆？',
					btn: ['退出'],
					yes: function(index) {
						window.AndroidWebView.sendBroad();
						layer.close(index);
					}
				});
			} else {
				successCallback(data);
			}
		},
		error: function() {
			hideLoading()
			console.log("请求失败")
			log_message("无数据")
			if(errorCallback) {
				errorCallback()
			}
		}
	});
}
//消息弹框
var timeId;

function log_message(message) {
	clearTimeout(timeId);
	if($('body').find('.log_message').length > 0) {
		$('body').find('.log_message').remove();
		$('body').append('<div class="log_message radius10P font1-2 LH2">' + message + '</div>');
		delete index;
	} else {
		$('body').append('<div class="log_message radius10P font1-2 LH2">' + message + '</div>');
		delete index;
	}
	timeId = setTimeout(function() {
		$('body').find('.log_message').remove();
	}, 3000)
}
//定位签到
var map_jingdu = "",
	map_weidu = "",
	map_address = "",
	lnglatXY = [];
var map, geolocation;

function dingwei() {
	map = new AMap.Map('', {});
	map.plugin('AMap.Geolocation', function() {
		geolocation = new AMap.Geolocation({
			enableHighAccuracy: true, //是否使用高精度定位，默认:true
			timeout: 10000, //超过10秒后停止定位，默认：无穷大
			buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
			zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
			buttonPosition: 'RB'
		});
		map.addControl(geolocation);
		geolocation.getCurrentPosition();
		AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
		AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
	});
}
//解析定位结果
function onComplete(data) {
	map_jingdu = data.position.getLng();
	map_weidu = data.position.getLat();
	lnglatXY.push(map_jingdu);
	lnglatXY.push(map_weidu);
	regeocoder();
}
//解析定位错误信息
function onError(data) {
	console.log('定位失败');
}

function regeocoder() { //逆地理编码
	var geocoder = new AMap.Geocoder({
		radius: 1000,
		extensions: "all"
	});
	geocoder.getAddress(lnglatXY, function(status, result) {
		if(status === 'complete' && result.info === 'OK') {
			geocoder_CallBack(result);
		}
	});
}

//function geocoder_CallBack(data) {
//	var address = data.regeocode.formattedAddress; //返回地址描述
//	console.log(address)
//	alert(jingdu + "经纬" + weidu)
//	alert(address)
//}